<template>
	<view>

		<view class="title">
			{{$t("authentication.identity-information")}}
		</view>


		<view class="input_pwd">
			<view class="tit">
				{{$t("address.name")}}:
			</view>
			<view class="" v-if="typePwd == 1">
				{{obj.realName}}
			</view>
			<view class="" v-else>
				<u-input v-model="valueName" :type="type" :border="border" :placeholder="placeholderReal"/>
			</view>
		</view>

		<view class="input_pwd">
			<view class="tit">
				{{$t("user.email")}}:
			</view>
			<view class="" v-if="typePwd == 1">
				{{obj.mail}}
			</view>
			<view class="" v-else>
				<u-input v-model="email" :type="type" :border="border"  :placeholder="placeholderReal"/>
			</view>
		</view>

<view class="input_pwd">
			<view class="tit">
				{{$t("authentication.certificate-type")}}:
			</view>
			<view class="" v-if="typePwd == 1">
				{{obj.credentialType==1?$t("authentication.driver-license"):$t("authentication.passport")}}
			</view>
			<view v-else>
				<u-radio-group v-model="value2">
					<u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.value">
						{{item.name}}
					</u-radio>
				</u-radio-group>
			</view>

		</view>

		<view class="input_pwd">
			<view class="tit">
				{{$t("authentication.certificate-no")}}:
			</view>
			<view class="" v-if="typePwd == 1">
				{{obj.credential}}
			</view>
			<view class="" v-else>
				<u-input v-model="value3" :type="type" :border="border" :password-icon="passwordIcon" :placeholder="placeholderReal"/>
			</view>
		</view>

		



		<view class="btn" v-if="typePwd == 1">
			<u-button type="primary" size="medium" @click="modify">{{$t("authentication.update")}}</u-button>
		</view>
		
	
		<view class="btn" v-else>
				<!-- <u-button type="default" size="medium" @click="back" style="margin-right: 20px;">{{$t("public.return")}}</u-button> -->
			
			<u-button type="primary" size="medium" @click="submit">{{$t("public.confirm")}}</u-button>
		</view>



	</view>
</template>
<script>
	import {
		realName
	} from '@/api/new.js';
	export default {

		data() {
			return {
				placeholderReal:this.$t('user.update.content'),
				typePwd: 3,
				value1: '',
				value2: 1,
				value3: '',
				type: 'text',
				passwordIcon: true,
				border: true,
				list: [{
					value: 1,
					name: this.$t("authentication.driver-license")
				}, {
					value: 2,
					name: this.$t("authentication.passport")
				}],
				value: this.$t("authentication.driver-license"),
				credential: '',
				credentialType: '',
				obj: {},
				valueName: '',
				email:''
			}

		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$t("authentication.title")
			})
			this.credentiald = uni.getStorageSync("USER_INFO")
			this.obj = JSON.parse(this.credentiald)
			// this.credentialType= uni.getStorageSync("USER_INFO").credentialType
			console.log(this.obj);
			this.valueName = this.obj.realName
			this.email = this.obj.mail
			this.value3 = this.obj.credential
			this.value2 = this.obj.credentialType==0?2:1
		},
		onShow() {

		},
		methods: {
			back(){
				this.typePwd = 1
			},
			radioChange(e) {

				this.value2 = e
				console.log(this.value2, '???');
			},
			confirm(e) {
				console.log(e);
			},
			modify() {
				this.typePwd = 2
			},
			submit() {

				if (this.valueName == '') return this.$util.Tips({
					title: this.$t('real.realname')
				});
				if (this.email == '') return this.$util.Tips({
					title: this.$t('real.email')
				});
				if (this.value3 == '') return this.$util.Tips({
					title: this.$t('real.num')
				});
				let that = this;
				let data = {
					realName: that.valueName,
					credential:  that.value3,
					credentialType: Number( that.value2),
					mail: that.email
				}
				realName(data).then(res => {
					console.log(res, 'res');
					that.$util.Tips({
						
						title: res.message=="实名认证成功"? this.$t('realName.success'):this.$t('auctionTips.2007')
					});
					// that.typePwd = 1
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/user/index'
						})
					}, 1000)

				}).catch(res => {
					that.$util.Tips({
						title: this.$t('auctionTips.2007')
					});
				});

			}
		}
	}
</script>
<style lang="scss">
	.title {
		margin: 45px 10px 0;
		font-size: 22px;
		font-weight: bold;
	}

	.input_pwd {
		display: flex;
		margin: 25px 10px 20px;
		align-items: center;

		.tit {
			font-weight: bold;
			font-size: 14px;
			margin-right: 10px;
		}

		.select {
			width: 150px;
			height: 35px;
		}
	}

	.placeholder {
		// color: #b9b9bc;
		border: 1px solid #ccc;
		padding: 20px;
	}

	.btn {
		display: flex;
		justify-content: center;
		margin-top: 50px;
	}
</style>